package com.k2.gulimall.member.service.impl;

import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.k2.common.utils.PageUtils;
import com.k2.common.utils.Query;

import com.k2.gulimall.member.dao.IntegrationChangeHistoryDao;
import com.k2.gulimall.member.entity.IntegrationChangeHistoryEntity;
import com.k2.gulimall.member.service.IntegrationChangeHistoryService;


@Service("integrationChangeHistoryService")
public class IntegrationChangeHistoryServiceImpl extends ServiceImpl<IntegrationChangeHistoryDao, IntegrationChangeHistoryEntity> implements IntegrationChangeHistoryService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<IntegrationChangeHistoryEntity> queryWrapper = new QueryWrapper<IntegrationChangeHistoryEntity>();
        if (params.get("memberId")!=null&&params.get("memberId").toString().length()>0) {
            queryWrapper.eq("member_id", params.get("memberId"));
        }
        if (params.get("sourceType")!=null&&params.get("sourceType").toString().length()>0) {
            queryWrapper.eq("source_tyoe", params.get("sourceType"));
        }
        if (params.get("createTime")!=null&&params.get("createTime").toString().length()>0) {
            try {
                String dateTime = params.get("createTime").toString();
                dateTime = dateTime.replace("Z", " UTC");
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
                String dateString = df.format(new Date());
                Date time = format.parse(dateTime);
                String result = df.format(time);
                queryWrapper.between("create_time",result,df.parse(dateString));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        IPage<IntegrationChangeHistoryEntity> page = this.page(
                new Query<IntegrationChangeHistoryEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }

}